import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/bangding',
    name: 'bangding',
    meta: {
      title: '绑定',
      keepAlive: false
    },
    component: () => import('../views/bangding.vue')
  },
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '首页',
      keepAlive: false
    },
    component: () => import('../views/login.vue')
  },
  {
    path: '/school_menu',
    name: 'school_menu',
    meta: {
      title: '智慧点餐',
      keepAlive: false
    },
    component: () => import('../views/school_menu.vue')
  },
  {
    path: '/login_api',
    name: 'login_api',
    meta: {
      title: '登录中....',
      keepAlive: false
    },
    component: () => import('../views/login_api.vue')
  },
  {
    path: '/bangding1',
    name: 'bangding1',
    meta: {
      title: '绑定信息',
      keepAlive: false
    },
    component: () => import('../views/bangding1.vue')
  },
  {
    path: '/bangding2',
    name: 'bangding2',
    meta: {
      title: '绑定信息',
      keepAlive: false
    },
    component: () => import('../views/bangding2.vue')
  },
  {
    path: '/index',
    name: 'index',
    meta: {
      title: '首页',
      keepAlive: false
    },
    component: () => import('../views/index.vue')
  },
  {
    path: '/isLogin',
    name: 'isLogin',
    meta: {
      title: '登录',
      keepAlive: false
    },
    component: () => import('../views/isLogin.vue')
  },
  {
    path: '/gerenxinxi',
    name: 'gerenxinxi',
    meta: {
      title: '我的信息',
      keepAlive: false
    },
    component: () => import('../views/gerenxinxi.vue')
  },
  {
    path: '/anzhuo',
    name: 'anzhuo',
    meta: {
      title: '下载',
      keepAlive: false
    },
    component: () => import('../views/anzhuo.vue')
  },
  {
    path: '/xiugaimima',
    name: 'xiugaimima',
    meta: {
      title: '修改密码',
      keepAlive: false
    },
    component: () => import('../views/xiugaimima.vue')
  }
]



const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior(to, from, savedPosition) { // 解决vue页面之间跳转，页面不是在顶部的问题
    return {x: 0, y: 0}
  }
})

router.beforeEach((to, form, next) => { //跳转前回调
  document.title = '怡启互联-' + to.matched[0].meta.title;
  next()
})

export default router
